﻿using Apps.Common;
using Apps.IBLL.RC;
using Apps.IBLL.Sys;
using Apps.Models;
using Apps.Web.Core;
using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Apps.Web.Areas.RC.Controllers
{
    public class SamplingRateController : BaseController
    {
        [Dependency]
        public IRC_SAMPLINGBLL m_SAMPLINGBBL { get; set; }
        [Dependency]
        public Apps.IBLL.PUB.IPUB_SUPPLIERBLL m_PUB_SUPPLIERBLL { get; set; }


        [Dependency]
        public Apps.IBLL.PUB.IPUB_MATERIELBLL m_PUB_MATERIELBLL { get; set; }

        [Dependency]
        public ISysUserBLL m_SysUserBLL { get; set; }

        [SupportFilter]
        public ActionResult Index()
        {
            //var List = m_PUB_SUPPLIERBLL.GetList(m=>m.ENABLED);
            //List.Insert(0, new Models.PUB.PUB_SUPPLIERModel { SUPPLIER_ID = "-1", SUPPLIER_NAME = "=========供应商=========" });
            ViewBag.SUPPLIER_ID = null;// new SelectList(List, "SUPPLIER_ID", "SUPPLIER_NAME");

            //var List2 = m_PUB_MATERIELBLL.GetList(m => m.PUB_MATERIEL_TYPE.IS_COAL == true);
            //List2.Insert(0, new Models.PUB.PUB_MATERIELModel { MATERIEL_ID = "-1", MATERIEL_NAME = "=========物 料=========" });
            ViewBag.MATERIEL_ID = null;// new SelectList(List2, "MATERIEL_ID", "MATERIEL_NAME");


            var List3 = m_SysUserBLL.GetList(ref GridPager.NotPage, "");
            List3.Insert(0, new Models.Sys.SysUserModel { Id = "-1", TrueName = "=========采样员=========" });
            ViewBag.SAMPLING_USER_ID = new SelectList(List3, "Id", "TrueName");

            ViewBag.StatisticalMethod = new List<SelectListItem>() { new SelectListItem { Text = "=========统计方式=========", Value = "-1" } };
            return View();
        }

        [HttpPost]
        [SupportFilter(ActionName = "Index")]
        public JsonResult GetListParent(GridPager pager, string MATERIEL_ID, string SAMPLING_USER_ID, string SUPPLIER_ID, string StatisticalMethod, string SAMPLING_BEGIN_TIME, string SAMPLING_END_TIME)
        {
            List<SamplingRateModel> list = new BLL.RC.RCSAMPLINGBLL().GetBLOCKList(MATERIEL_ID, SAMPLING_USER_ID, SUPPLIER_ID, StatisticalMethod, SAMPLING_BEGIN_TIME, SAMPLING_END_TIME);
            GridRows<SamplingRateModel> grs = new GridRows<SamplingRateModel>();
            grs.rows = list;
            grs.total = pager.totalRows;
            return Json(grs);
        }
    }
}